import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt(), M = scanner.nextInt(), S = scanner.nextInt();
        Queue<Character>[] queues = new Queue[N + 1];
        Stack<Character> stack = new Stack<>();
        String[] arr = new String[N + 1];
        //存入队列中
        for (int i = 1; i <= N; i++) {
            arr[i] = scanner.next();
            queues[i] = new LinkedList<>();
            for (int j = 0; j < M; j++) {
                queues[i].offer(arr[i].charAt(j));
            }
        }
        while (scanner.hasNext()) {
            int num = scanner.nextInt();
            if(num == 3) {
                if(!queues[num].isEmpty()) {
                    char x = queues[num].poll();
                    stack.push(x);
                } else continue;
            } else if(num == 2) {
                if(!queues[num].isEmpty()) {
                    char x = queues[num].poll();
                    stack.push(x);
                } else continue;
            } else if(num == 1) {
                if(!queues[num].isEmpty()) {
                    char x = queues[num].poll();
                    stack.push(x);
                }
            } else if(num == 0) {
                char x = stack.pop();
                System.out.print(x);
            } else break;
        }
    }
}